/**
 * id可以是数字,[id:2,id:3]
 * 
 * @param id
 * @param element
 * @param type
 * @param open
 * @returns
 */
function departmentTree(id, element, type,open) {
	var ids = new Array();
	if (typeof id === 'number')
		ids.push(id);
	else 
	{
		ids = id;
	}
	this.open = open;
	this.type = type || -1;
	this.element = element;
	var setting = {};

	this.init = function(opt) {
		var tmp = {
			id : ids,
			type : type
		};
		var self = this;
		commitData(ctx + '/department/json.htm', tmp, {
			success : function(data) {
				if(typeof data === "string")
					data = JSON.parse(data);
				var department = new Array();
				$.each(data, function(index, value) {
					if (index == 0) {// 返回第一个id用于默认显示
						if (opt.callback && opt.callback.onComplete) {
							opt.callback.onComplete(value.id);
						}
					}
					var obj = {
						id : value.id,
						pId : value.parentId,
						name : value.shortname
					};
					obj.open = self.open;
					department.push(obj);
				});
				$.extend(setting, opt);
				new mytree($(element || "#treeUnit"), department, opt).init();
			}
		});
	}
}


function departmentRoleTree(id, element, type,open) {
	var ids = new Array();
	if (typeof id === 'number')
		ids.push(id);
	else 
	{
		ids = id;
	}
	this.open = open;
	this.type = type || -1;
	this.element = element;
	var setting = {};

	this.init = function(opt) {
		var tmp = {
			id : ids,
			type : type
		};
		var self = this;
		commitData(ctx + '/department/rolejson.htm', tmp, {
			success : function(data) {
				var department = new Array();
				$.each(data, function(index, value) {
					if (index == 0) {// 返回第一个id用于默认显示
						if (opt.callback && opt.callback.onComplete) {
							opt.callback.onComplete(value.id);
						}
					}
					
					/*
					var strid;
					if(value.rolekey==''||value.rolekey==null){
						strid=value.id;
					}
					else{
						strid= "role" + value.rolekey;
					}*/
					
					var obj = {
						id : value.id,
						pId : value.parentId,
						name : value.shortname,
						rolekey:value.rolekey
					};
					
					obj.open = self.open;
					department.push(obj);
				});
				$.extend(setting, opt);
				new mytree($(element || "#treeUnit"), department, opt).init();
			}
		});
	}
}